package leetcodecompetition.S108;

/**
 * @Author: Siantar
 * @Date: 2023-07-08-22:32
 * @Description: 1.0
 */
public class T6913 {
    public int alternatingSubarray(int[] nums) {
        int res = 0;
        for (int i = 1; i < nums.length; i++) {
            int ii = i;
            int sum = 0;
            int a = 1;
            while (ii < nums.length && nums[ii - 1] + a == nums[ii]) {
                a = -a;
                sum++;
                ii++;
            }
            res = Math.max(res, sum);
        }
        return res == 0 ? -1 : res + 1;
    }
}
